//Accepted
//http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=951
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <iostream>
#include <list>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

int n, m, i, j, k, a, t, s[20], x[20][2], v[8][2]={{0,1},{0,-1},{1,0},{-1,0},{1,1},{-1,-1},{1,-1},{-1,1}}, d, ii, jj, ss, kk;
char p[50][55];
char q[20][55];
bool b[20], ok;
int main (){
	//freopen("in.txt", "r", stdin);//freopen("out.txt", "w", stdout);
	scanf("%d", &t);
	while(t--){
		
		scanf("%d%d", &n, &m);
		for(i=0;i<n;++i){
			scanf("%s", p[i]);
			//printf("%s\n", p[i]);
	 	}
		scanf("%d", &k);
		for(i=0;i<k;++i){
			scanf("%s", q[i]);
			s[i]=strlen(q[i]);
			b[i]=1;
		}
		for(i=0;i<n;++i){
			for(j=0;j<m;++j){
				for(a=0;a<k;++a){
					if(b[a]){//find
						for(d=0;d<8&&b[a];++d){
							ok=1;
							ii=i;
							jj=j;
							for(kk=0;  (kk<s[a])  &&  (0<=ii&&ii<n)  &&  (0<=jj&&jj<m)  ;  ++kk){
								if(toupper(q[a][kk])!=toupper(p[ii][jj])){
									ok=0;
									break;
								}
								ii+=v[d][0];
								jj+=v[d][1];
							}
							if(ok&&(kk==s[a])){
								x[a][0]=i;
								x[a][1]=j;
								b[a]=0;
							}
						}
						
					}
				}
			}
		}
		for(i=0;i<k;++i){
			printf("%d %d\n", x[i][0]+1, x[i][1]+1);
		}
		if(t)printf("\n");
	}
	return 0;
}
